(function($) {
	$.getUrlParam = function(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
	}
})(jQuery);

const payState = S = {
	init: function() {
		// 初始化

		S.render();
	},
	// 支付成功
	update: function() {

	},
	render: function() {
		var id = $.getUrlParam("did");
		var trade_no = $.getUrlParam('trade_no');
		var out_trade_no = $.getUrlParam('out_trade_no');
		$.ajax({
			url: url.path + 'taoqian/queryPay',
			type: 'post',
			data: {
				WIDTQout_trade_no: out_trade_no,
				WIDTQtrade_no: trade_no
			},
			success: function(res) {
				var res = eval("(" + res + ")");
				console.log('交易==>', res);
				var send_pay_date = res.alipay_trade_query_response.send_pay_date;
				var total_amount = res.alipay_trade_query_response.total_amount;
				if (res.alipay_trade_query_response.code == 10000) {
					if (res.alipay_trade_query_response.trade_status == "TRADE_SUCCESS") {
						//支付成功
						window.location.href = 'paySuccess.html?&out_trade_no=' + out_trade_no +
							'&total_amount=' + total_amount +
							'&send_pay_date=' + send_pay_date
					} else {
						window.location.href = 'payFail.html?&trade_no=' + trade_no +
							'&out_trade_no' + out_trade_no
					}
				} else {
					alert(res.msg);
				}
			}
		});
	}
}
$(function() {
	S.init();
})